using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace ScavengerHunt
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Menus : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Texture2D splash, team, credits;
        SpriteFont menuFont;
        enum GameScreens { Splash, Team, MainMenu, Game, Options, Paused, Credits };
        enum Selection { PlayGame, Options, Credits, Quit };
        GameScreens screen = 0;
        Selection select = 0;
        Rectangle wholeWindow;
        Vector2 center;
        Game wtfgame;
        public Menus(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
            wtfgame = game;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            wholeWindow = new Rectangle(0, 0, Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height);
            screen = GameScreens.Splash;
            splash = Game.Content.Load<Texture2D>("Images\\10753");
            team = Game.Content.Load<Texture2D>("Images\\JointEffort");
            credits = Game.Content.Load<Texture2D>("Images\\ScavengerCredits");
            menuFont = Game.Content.Load<SpriteFont>("Menu");
            center = new Vector2(Game.Window.ClientBounds.Width / 2, Game.Window.ClientBounds.Height / 2);
            base.Initialize();
        }

        protected override void LoadContent()
        {  
            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            switch (screen)
            {
                case(GameScreens.Splash):
                    {
                        if (gameTime.TotalGameTime.Seconds > 2)
                        { screen = GameScreens.Team; }
                        break;
                    }
                case (GameScreens.Team):
                    {
                        if (gameTime.TotalGameTime.Seconds > 4)
                        { screen = GameScreens.MainMenu; }
                        break;
                    }
                case (GameScreens.MainMenu):
                    {
                        select = Selection.PlayGame;
                        if (gameTime.TotalGameTime.Seconds > 6)
                        { screen = GameScreens.Game; }
                        /*switch (select)
                        {
                            case (Selection.PlayGame):
                                {
                                    screen = GameScreens.Game;
                                    break;
                                }
                            case (Selection.Options):
                                {
                                    screen = GameScreens.Options;
                                    break;
                                }
                            case (Selection.Credits):
                                {
                                    screen = GameScreens.Credits;
                                    break;
                                }
                            case (Selection.Quit):
                                {
                                    Game.Exit();
                                    break;
                                }
                        }*/
                        break;
                    }
                case (GameScreens.Game):
                    {
                        break;
                    }
                case (GameScreens.Paused):
                    { break; }
                case (GameScreens.Credits):
                    {

                        break; }
                default: break;
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = Game.Services.GetService(typeof(SpriteBatch)) as SpriteBatch;
            string mainMenuPlaceholder = "Main Menu Goes here";

            switch (screen)
            {
                case (GameScreens.Splash):
                    {
                        spriteBatch.Begin();
                        spriteBatch.Draw(splash, wholeWindow, Color.White);
                        spriteBatch.End();
                        break;
                    }
                case (GameScreens.Team):
                    {
                        spriteBatch.Begin();
                        spriteBatch.Draw(team, wholeWindow, Color.White);
                        spriteBatch.End();
                        break;
                    }
                case (GameScreens.MainMenu):
                    {
                        spriteBatch.Begin();
                        spriteBatch.DrawString(menuFont, mainMenuPlaceholder, new Vector2(center.X - menuFont.MeasureString(mainMenuPlaceholder).X, center.Y - menuFont.MeasureString(mainMenuPlaceholder).Y), Color.Violet);
                        spriteBatch.End();
                        break; }
                case (GameScreens.Game):
                    {
                        Game.Components.Add(new VoidBunny(wtfgame, camera));
                        break;
                    }
                case (GameScreens.Paused):
                    { break; }
                case (GameScreens.Credits):
                    {
                        spriteBatch.Begin();
                        spriteBatch.Draw(credits, wholeWindow, Color.White);
                        spriteBatch.End();
                        break;
                    }
            }

            base.Draw(gameTime);
        }
    }
}
